﻿using System;
using System.Diagnostics.Contracts;

namespace Postnuclear.Collections
  {
  /// <summary>
  /// The event arguments for the events which notify about change of item in observable collections.
  /// </summary>
  /// <typeparam name="T">The type of the elements in the collection.</typeparam>
  public sealed class ObservableItemEventArgs<T>
    : EventArgs
    {
    #region Public

    // Constructor

    /// <summary>
    /// Initializes a new instance of the <see cref="ObservableItemEventArgs{T}"/> class.
    /// </summary>
    /// <param name="item">The added/removed item.</param>
    /// <param name="index">The items index.</param>
    public ObservableItemEventArgs(T item, int index)
      {
      Contract.Requires<ArgumentOutOfRangeException>(index >= 0);

      Contract.Ensures(object.Equals(Item, item));
      Contract.Ensures(object.Equals(Index, index));

      Item = item;
      Index = index;
      }

    // Fields

    /// <summary>
    /// Gets items.
    /// </summary>
    public readonly T Item;

    /// <summary>
    /// Gets items index.
    /// </summary>
    public readonly int Index;

    #endregion
    }
  }